package com.ruoyi.web.controller.module.asset;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.system.domain.module.asset.EstateAssetInfo;
import com.ruoyi.system.service.module.asset.IEstateAssetInfoService;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.web.controller.common.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 固定资产盘点任务详情Controller
 *
 * @author ruoyi
 * @date 2025-02-17
 */
@Validated
@Api(value = "固定资产盘点任务详情控制器", tags = {"固定资产盘点任务详情管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/module/assetPlanInfo")
public class EstateAssetInfoController extends BaseController {

    private final IEstateAssetInfoService estateAssetInfoService;

    /**
     * 查询固定资产盘点任务详情列表
     */
    @ApiOperation("查询固定资产盘点任务详情列表")
    @PreAuthorize("@ss.hasPermi('module:assetPlanInfo:list')")
    @GetMapping("/list")
    public TableDataInfo<EstateAssetInfo> list(@Validated EstateAssetInfo estateAssetInfo) {
        QueryWrapper<EstateAssetInfo> qw = new QueryWrapper<>();

        TableDataInfo<EstateAssetInfo> td = PageUtils.buildDataInfo(estateAssetInfoService.page(PageUtils.buildPage(),qw));
        List<EstateAssetInfo> list = td.getRows();
        return td;
    }

    /**
     * 导出固定资产盘点任务详情列表
     */
    @ApiOperation("导出固定资产盘点任务详情列表")
    @PreAuthorize("@ss.hasPermi('module:assetPlanInfo:export')")
    @Log(title = "固定资产盘点任务详情", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<EstateAssetInfo> export(@Validated EstateAssetInfo estateAssetInfo) {
        List<EstateAssetInfo> list = estateAssetInfoService.list();
        ExcelUtil<EstateAssetInfo> util = new ExcelUtil<EstateAssetInfo>(EstateAssetInfo.class);
        return util.exportExcel(list, "固定资产盘点任务详情");
    }

    /**
     * 获取固定资产盘点任务详情详细信息
     */
    @ApiOperation("获取固定资产盘点任务详情详细信息")
    @PreAuthorize("@ss.hasPermi('module:assetPlanInfo:query')")
    @GetMapping("/{id}")
    public AjaxResult<EstateAssetInfo> getInfo(@NotNull(message = "主键不能为空") @PathVariable("id") Long id) {
        EstateAssetInfo estateAssetInfo = estateAssetInfoService.getById(id);
        return AjaxResult.success(estateAssetInfo);
    }

    /**
     * 新增固定资产盘点任务详情
     */
    @ApiOperation("新增固定资产盘点任务详情")
    @PreAuthorize("@ss.hasPermi('module:assetPlanInfo:add')")
    @Log(title = "固定资产盘点任务详情", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody EstateAssetInfo estateAssetInfo) {
        return toAjax(estateAssetInfoService.save(estateAssetInfo) ? 1 : 0);
    }

    /**
     * 修改固定资产盘点任务详情
     */
    @ApiOperation("修改固定资产盘点任务详情")
    @PreAuthorize("@ss.hasPermi('module:assetPlanInfo:edit')")
    @Log(title = "固定资产盘点任务详情", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody EstateAssetInfo estateAssetInfo) {
        return toAjax(estateAssetInfoService.updateById(estateAssetInfo) ? 1 : 0);
    }

    /**
     * 删除固定资产盘点任务详情
     */
    @ApiOperation("删除固定资产盘点任务详情")
    @PreAuthorize("@ss.hasPermi('module:assetPlanInfo:remove')")
    @Log(title = "固定资产盘点任务详情" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")  @PathVariable Long[] ids) {
        return toAjax(estateAssetInfoService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
